﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class SiteMaster : System.Web.UI.MasterPage
{
    BankDataDataContext db = new BankDataDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        MembershipUser user =  Membership.GetUser();
        if (user != null)
        {
            if (Roles.IsUserInRole("User"))
            {
                PanelLink.Text = "Панель пользователя";
                PanelLink.NavigateUrl = "~/User/UserPanel.aspx";
                PanelLink.Visible = true;
            }
            if (Roles.IsUserInRole("Operator"))
            {
                PanelLink.Text = "Панель оператора";
                PanelLink.NavigateUrl = "~/Operator/OperatorPanel.aspx";
                PanelLink.Visible = true;
            }
            if (Roles.IsUserInRole("Administrator"))
            {
                PanelLink.Text = "Панель администратора";
                PanelLink.NavigateUrl = "~/Admin/Admin.aspx";
                PanelLink.Visible = true;
            }
        }
        else
        {
            Session.Remove("companyId");
            Session.Remove("profileId");
            Session.Remove("clientId");
        }
        MenuItem creditsMenu = new MenuItem();
        creditsMenu.Text="Кредиты";
        creditsMenu.Value = "-1";
        foreach (Credit credit in db.Credits)
        {
            if ((bool)credit.Active)
            {
                MenuItem creditMenu = new MenuItem();
                creditMenu.Text = credit.Name;
                creditMenu.Value = credit.CreditID.ToString();
                creditsMenu.ChildItems.Add(creditMenu);
            }
        }
        NavigationMenu.Items.Add(creditsMenu);
    }

    protected void NavigationMenu_MenuItemClick(object sender, MenuEventArgs e)
    {
        MenuItem creditMenu = e.Item;
        if (creditMenu.Value == "-1")
        {
            Response.Redirect("~/Default.aspx");
        }
        Session.Add("creditMenuId", creditMenu.Value);
        Response.Redirect("~/Credit.aspx");
    }
}
